package com.magenta.maxoptra.gis.distancematrix.commands;

import com.magenta.maxoptra.gis.distancematrix.CommandType;
import com.magenta.maxoptra.gis.distancematrix.DistanceMatrixDAO;
import com.magenta.maxoptra.gis.distancematrix.DistanceMatrixServiceProxy;
import com.magenta.maxoptra.gis.distancematrix.UpdateRequestType;

/**
 * @author Sergey Grachev
 */
final class ChangeUpdateTimeInterval extends AbstractGroupCommand {

    private final int from;
    private final int to;

    ChangeUpdateTimeInterval(final long groupId, final int from, final int to) {
        super(groupId);
        this.from = from;
        this.to = to;
    }

    @Override
    public CommandType getType() {
        return CommandType.CHANGE_UPDATE_TIME_INTERVAL;
    }

    @Override
    public void execute(final DistanceMatrixDAO db, final DistanceMatrixServiceProxy service) {
        groupContext.setTimeInterval(from, to);
    }

    @Override
    public UpdateRequestType isRequireMatrixUpdating() {
        return UpdateRequestType.NONE;
    }

    @Override
    public boolean isRequireGroupLock() {
        return false;
    }

    @Override
    public String toString() {
        return "ChangeUpdateTimeInterval{" +
                "groupId=" + groupId +
                ", from=" + from +
                ", to=" + to +
                '}';
    }
}

